<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysqli.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
if(!$memberid=is_login($link)){
    $url=urlencode("$_SERVER[REQUEST_URI]");
    skip("login.php?url={$url}",'error','请登陆之后再进行发帖！');
}
if(isset($_POST['submit'])){
    $_POST=tosqlstring($link,$_POST);
include_once 'inc/checkPublish.php';
$query="insert into content(cmid,title,content,time,memberid) values({$_POST['cmid']},'{$_POST['title']}','{$_POST['content']}',now(),$memberid)";
$result=execute($link,$query);
if(mysqli_affected_rows($link)==1){
    skip("$_SERVER[REQUEST_URI]",'ok','发布成功！ ');
  }else{
    skip("$_SERVER[REQUEST_URI]",'error','发布失败，请重试！ ');
  }
}







$template='帖子发布';
include_once 'inc/header.inc.php';
?>



        <div class="pbmain">
            <div class="wrap">
                <h2 class="top_dir">
                    <a href="index.php">首页</a>
                    <?php
                     
                     if(isset($_GET['cmid'])){
                         if(is_numeric($_GET['cmid'])||$_GET['cmid']>1){
                             $queryc="select *from childModule where id={$_GET['cmid']}";
                             $result=execute($link,$queryc);
                            if(mysqli_num_rows($result)){                               
                                $datac=mysqli_fetch_assoc($result);
                                $datac=dehtml($datac);
                                $queryf="select *from fatherModule where id={$datac['referid']}";
                                $result=execute($link,$queryf);
                                $dataf=mysqli_fetch_assoc($result);
                                $dataf=dehtml($dataf);
                                echo "&nbsp;&gt;<a href='parentList.php?id={$dataf['id']}'>{$dataf['moduleName']}</a>&nbsp;&gt;<a href='childList.php?id={$datac['id']}'>{$datac['moduleName']}</a>";
                            }                           
                         }      
                    }elseif(isset($_GET['fmid'])){ 
                        if(is_numeric($_GET['cmid'])||$_GET['cmid']>1){
                            $queryf="select *from fatherModule where id={$_GET['fmid']}";
                            $result=execute($link,$queryf);  
                            if(mysqli_num_rows($result)){                                                                     
                                $dataf=mysqli_fetch_assoc($result);
                                $dataf=dehtml($dataf); 
                                echo "&nbsp;&gt;<a href='parentList.php?id={$dataf['id']}'>{$dataf['moduleName']}</a>";                  
                            }
                        }
                    }
                    ?>
                    &gt;&nbsp;<span>发布帖子</span>
                    
                </h2>
                <div class="content">
                    <form method="post">
                        <select name="cmid">
                            <option>请选择一个板块</option>
                            <?php
                            $queryf="select *from fatherModule order by sort desc";
                            $resultf=execute($link,$queryf);
                            while($dataf=mysqli_fetch_assoc($resultf)){
                                echo "<optgroup label='{$dataf['moduleName']}'>";
                                $query="select *from childModule where referid={$dataf['id']}";
                                $result=execute($link,$query);
                                while($data=mysqli_fetch_assoc($result)){
                                    if($data['id']==$_GET['cmid']){
                                        echo "<option value='$data[id]' selected='selected' >{$data['moduleName']}</option>";
                                    }else{
                                        echo "<option value='$data[id]' >{$data['moduleName']}</option>";
                                    }
                                    
                                }
                                echo "</optgroup>";
                            }

                            ?>

                        </select>
                        <input type="text" placeholder="请输入标题" name="title" class="title">
                        <textarea name="content" class="text_part" ></textarea>
                        <input type="submit" name="submit" value="发布" class="nsubmit">
                    </form>
                </div>
            </div>
        </div>
    
        



 <?php
include_once 'inc/footer.inc.php';
?>